package com.party.core.service.partner.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.partner.MemberPartnerPrivilegeReadDao;
import com.party.core.dao.write.partner.MemberPartnerPrivilegeWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.partner.MemberPartnerPrivilege;
import com.party.core.service.partner.IMemberPartnerPrivilegeService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 合作商
 *
 * @author yifeng
 * @date 2018/8/7 0007
 * @time 下午 13:53
 */
@Service
public class MemberPartnerPrivilegeService implements IMemberPartnerPrivilegeService {
    @Autowired
    private MemberPartnerPrivilegeReadDao memberPartnerPrivilegeReadDao;
    @Autowired
    private MemberPartnerPrivilegeWriteDao memberPartnerPrivilegeWriteDao;

    @Override
    public String insert(MemberPartnerPrivilege memberPartnerPrivilege) {
        BaseModel.preInsert(memberPartnerPrivilege);
        boolean result = memberPartnerPrivilegeWriteDao.insert(memberPartnerPrivilege);
        if (result) {
            return memberPartnerPrivilege.getId();
        }
        return null;
    }

    @Override
    public boolean update(MemberPartnerPrivilege memberPartnerPrivilege) {
        return memberPartnerPrivilegeWriteDao.update(memberPartnerPrivilege);
    }

    @Override
    public boolean deleteLogic(String id) {
        return false;
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return memberPartnerPrivilegeWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return memberPartnerPrivilegeWriteDao.batchDelete(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        return false;
    }

    @Override
    public MemberPartnerPrivilege get(String id) {
        return memberPartnerPrivilegeReadDao.get(id);
    }

    @Override
    public List<MemberPartnerPrivilege> listPage(MemberPartnerPrivilege memberPartnerPrivilege, Page page) {
        return memberPartnerPrivilegeReadDao.listPage(memberPartnerPrivilege, page);
    }

    @Override
    public List<MemberPartnerPrivilege> list(MemberPartnerPrivilege memberPartnerPrivilege) {
        return memberPartnerPrivilegeReadDao.listPage(memberPartnerPrivilege, null);
    }

    @Override
    public List<MemberPartnerPrivilege> batchList(Set<String> ids, MemberPartnerPrivilege memberPartnerPrivilege, Page page) {
        return null;
    }

    @Override
    public List<Map<String, String>> findByPartnerId(String partnerId) {
        return memberPartnerPrivilegeReadDao.findByPartnerId(partnerId);
    }

    @Override
    public List<Map<String, String>> findByMemberId(String initiatorId) {
        return memberPartnerPrivilegeReadDao.findByMemberId(initiatorId);
    }

    @Override
    public void deleteByPartnerId(String partnerId) {
        memberPartnerPrivilegeWriteDao.deleteByPartnerId(partnerId);
    }

    @Override
    public void deleteByMemberId(String memberId) {
        memberPartnerPrivilegeWriteDao.deleteByMemberId(memberId);
    }
}
